﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Clear();//清空ListBox控件
        int p = 0, n = 0, a = 1, b = 1;//定义变量
        try
        {
            p = Convert.ToInt32(TextBox1.Text);//将字符型转换成数值型
        }
        catch//出现错误
        {
            Response.Write("<script>alert('请输入数值型数据');</script>");
            TextBox1.Text = "15";
            return;
        }
        while(a<p)//对输入的数值进行遍历
        {
            ListBox1.Items.Add(a.ToString());//输出数值
            ListBox1.Items.Add(b.ToString());//输出数值
            a = a + b;//获取前两个数的和
            b = a + b;//获取前两个数的和
        }
    }
}
